/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package searchspads;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.*;
import org.sqlite.SQLiteConfig;
import org.sqlite.SQLiteDataSource;

/**
 *
 * @author VANHUNG
 */
public class BoTuongThich {
   
    private static Connection con = null;
    private static SQLiteConfig config;
    private static SQLiteDataSource ds;
    
    public static Connection KetNoi(){
        //Driver driver = new com.microsoft.sqlserver.jdbc.SQLServerDriver();
         Statement stmt = null;
        try {
          
//          DriverManager.registerDriver(driver);
//          con = DriverManager.getConnection("jdbc:sqlserver://localhost:1433;databaseName=kensaku;user=sa;password=123456a@");

//         Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//         String strURL = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};DBQ=" + "src\\data\\kensaku.accdb";   
//         con = DriverManager.getConnection(strURL);
            
            Class.forName("org.sqlite.JDBC");
            config = new SQLiteConfig();
            config.enableFullSync(true);
            config.setReadOnly(false);
            ds = new SQLiteDataSource(config);
            ds.setUrl("jdbc:sqlite::resource:resources/kensaku.jar");
            con = ds.getConnection();
            if(con !=null){
                 System.out.println("Opened database successfully");
            }else{
                 System.out.println("Opened database err");
            }
            
         ResultSet rs = stmt.executeQuery( "SELECT * FROM session" );
        
      stmt.close();
      con.close();
        } catch (Exception e) {
            System.out.println(e.getMessage());
        }
        return con;
}
    
    public static void DongKetNoi(){
        try {
            if(con != null)
                con.close();
        } catch (Exception e) {
        }
    }

 public static void executeUpdate(PreparedStatement pr){
     try {
         pr.executeUpdate();
     } catch (Exception e) {
     }
 }
 
 public static ResultSet executeQuery(String sql){
     ResultSet rs = null;
     
     try {
         con = KetNoi();
         Statement st = con.createStatement();
         rs = st.executeQuery(sql);
     } catch (Exception e) {
     }
     
     return rs;
 }
}
